<!--
 * @Author: Cenven
 * @Date: 2021-03-16 15:08:13
 * @Description: 北京泓深教育发展有限公司
 * @Descripttion: 
 * @version: @Lastest
 * @LastEditTime: 2021-09-29 14:37:29
 * @CopyRight: 北京泓深教育发展有限公司
-->
<template>
  <div class="componet-mobile_question-card" @click="toPath">
    <div class="tags" v-if="is_lastest">新</div>
    <img
      class="icon_path"
      v-lazy="(item && item.cover) || '/img/mobile/question_menus_subject.png'"
    />
    <div class="question_name">
      {{ item && item.questionGroupName }}
    </div>
    <div class="question_price" v-if="!is_hidden_content">
      <!-- 免费 -->
      <span v-if="isMemberFreeQuestion" class="free">会员免费</span>
      <span v-else-if="item && item.isFree" class="free">免费</span>
      <span v-else>
        <!-- 带折扣开始 -->
        <template v-if="item && isDiscount">
          <span class="old_price"
            >￥{{ (item && item.price) + "元" || "未知" }}
            <!-- 购买后是长期的不显示年限 -->
            <!-- <template v-if="item && item.effectiveTime">
              /{{ (item && item.effectiveTime) || "未知" }}年
            </template> -->
          </span>
          <span class="new_price"
            >￥<span style="font-weight: bold;font-size: .24rem;"
              >{{ (item && item.discountPrice) + "元" || "未知" }}
              <!-- 购买后是长期的不显示年限 -->
              <template v-if="item && item.effectiveTime">
                /{{ (item && item.effectiveTime) || "未知" }}年
              </template>
            </span>
          </span>
        </template>
        <!-- 带折扣结束 -->

        <!-- 不带折扣开始 -->
        <template v-else>
          <span class="new_price"
            >￥<span style="font-weight: bold;font-size: .24rem;"
              >{{ (item && item.price) + "元" || "未知" }}
              <!-- 购买后是长期的不显示年限 -->
              <template v-if="item && item.effectiveTime">
                /{{ (item && item.effectiveTime) || "未知" }}年
              </template>
            </span></span
          >
        </template>
        <!-- 不带折扣结束 -->
      </span>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions, mapMutations } from "vuex";
export default {
  props: ["item"],
  components: {},
  data() {
    return {};
  },
  computed: {
    ...mapState({
      is_hidden_content(state) {
        return state.is_hidden_content;
      },
      is_wechat_ios_limit(state) {
        return state.is_wechat_ios_limit;
      },
      is_hidden_for_ios(state) {
        return state.is_hidden_for_ios;
      },
      member_discount(state) {
        return state.member_discount;
      },
    }),
    // 是否会员免费题库
    isMemberFreeQuestion(){
      if(Object.keys(this.member_discount).length > 0){
        const { deleted , questionGroupIds } = this.member_discount;
        return deleted == 0 && questionGroupIds.includes(this.item.id);
      }else{
        return false;
      }
    },
    is_lastest() {
      let create_time = new Date(this.item.createTime).getTime();
      let current_time = new Date().getTime();
      if (current_time - create_time <= 7 * 24 * 60 * 60) {
        return 1;
      } else {
        return 0;
      }
    },
    isDiscount() {
      if (this.item.isDiscount == 1) {
        let current_time = new Date().getTime();
        let discount_start_time = new Date(
          this.item.discountStartTime
        ).getTime();
        let discount_end_time = new Date(
          this.item.discountEndTime
        ).getTime();
        return (
          discount_start_time <= current_time &&
          current_time < discount_end_time
        );
      } else {
        return false;
      }
    },
  },
  watch: {},
  methods: {
    toPath() {
      this.$router.push({ path: "/m/v2-question-detail?id=" + this.item.id });
    }
  },
  created() {},
  mounted() {}
};
</script>

<style lang="scss">
.componet-mobile_question-card {
  width: 3.15rem;
  margin-left: 0.3rem;
  margin-top: 0.3rem;
  float: left;
  height: 3.3rem;
  background-color: #ffffff;
  border-radius: 0.1rem;
  overflow: hidden;
  position: relative;
  .tags {
    position: absolute;
    left: 0;
    top: 0;
    width: 2rem;
    height: 0.4rem;
    background: #ff6868;
    color: #ffffff;
    text-align: center;
    font-size: 0.3rem;
    line-height: 0.4rem;
    transform: rotateZ(319deg) translateX(-27%) translateY(-40%);
  }
  .icon_path {
    width: 3.15rem;
    height: 2.1rem;
    display: block;
    background: var(--theme-color);
  }
  .question_name {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 0.2496rem;
    color: #7c7d80;
    padding: 0.1536rem 0.1536rem 0;
  }
  .question_price {
    font-size: 0.2496rem;
    text-align: right;
    padding: 0.1536rem 0.1536rem 0;
    white-space: nowrap;
    .free {
      color: var(--theme-color);
    }
    .old_price {
      color: #c6c8cc;
      text-decoration: line-through;
      font-size: 0.2rem;
    }
    .new_price {
      margin-left: 0.1rem;
      color: var(--theme-color);
    }
  }
}
</style>
